<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,member-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />

<title></title>
</head>
<body>
<div class="pd-20">
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
	<!-- <a href="javascript:;" onclick="datadelall()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>  -->
	</span> <span class="r">共有数据：<strong id="sum">0</strong> 条</span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="comments" value=""></th>
					<th width="60">评论用户</th>
					<th>评论内容</th>
					<th width="100">评论时间</th>
					<th width="100">操作</th>
				</tr>
			</thead>

		 	<tbody id="str">
			<!-- 	<tr class="text-c">
					<td><input type="checkbox" value="2" name="comments"></td>

					<td>张三</td>
					<td>评论内容</td>
					<td>2015-6-9</td>
					<td class="td-manage"><a title="删除" href="javascript:;" onclick="member_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
				</tr>
 -->
				
				
			</tbody> 

			<tbody id="str">
			</tbody>
		</table>
	</div>
</div>
<div id="page1" style="float: right;"></div>
<div style="clear: both;"></div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript">
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
  }


$(function(){
	update();
	demo();
});
//以下将以jquery.ajax为例，演示一个异步分页
function demo(curr){
	var sid = getQueryString("sid");

	$.ajax( {  
	     url:'/baby/comment/queryComment',// 跳转到 action  
	     data:{pageNum:curr,key:sid},  
	     type:'post',  
	     cache:false,  
	     dataType:'json',  
	     success:function(data) { 
	     	if(data.code =="2000" ){ 
	             // alert(data.data.totalRowNumber); 
	             console.log(data);
	             if(data.data == null){
	             	// alert(data.message);
	             	 var htmlstr='';
	             	 htmlstr+='<tr class="text-c">'
	             	 	+'<th colspan="5" style="color:red;">还没有评论</th></tr>'
	             	 document.getElementById("str").innerHTML =htmlstr 
	             	return;
	             }
	             var datalist= data.data.dataList;
	             //拼页面
	             var s=data.data.totalRowNumber;
	             document.getElementById("sum").innerHTML=s
	            
	             var htmlstr='';
	             for (var i=0;i<datalist.length;i++){
	             	var obj = datalist[i];//获取单个数据对象
	             	var sid = '\'' +obj.sid+ '\'';
	             	htmlstr+='<tr class="text-c">'
					
					+'<td><input type="checkbox" value="" name="comments"></td>'

					+'<td>'+obj.user.userName+'</td>'
					+'<td>'+obj.commentMsg+'</td>'
					+'<td>'+obj.commentCreateTime+'</td>'
					+'<td class="td-manage"><a title="删除" href="javascript:;" onclick="comment_del(this,\''+obj.sid+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>'
					+'</tr>'

	             }
	            document.getElementById("str").innerHTML =htmlstr 
	            laypage({
				    cont: $('#page1'), //容器。值支持id名、原生dom对象，jquery对象,
				    pages:data.data.totalRowNumber, //总页数
				    skip: true, //是否开启跳页
				    groups: 5, //连续显示分页数
				    curr: data.data.currentPage, //当前页
				    pages:data.data.totalPage,
				    jump: function(obj, first){
				    //得到了当前页，用于向服务端请求对应数据
				    var curr = obj.curr;
				    if(!first){
				    	demo(curr);	
				    }
				}
			});
	        }else{  
	        	alert(data.message); 
	        	console.log(data);  
	        }  
	    }, 
	    error : function() {      
	    	alert("异常！");  
	    }  
	});
};
//运行
//修改状态
function update(){
var sid = getQueryString("sid");

	$.ajax( {  
	     url:'/baby/comment/updateComment',// 跳转到 action  
	     data:{key:sid},  
	     type:'post',  
	     cache:false,  
	     dataType:'json',  
	     success:function(data) { 
	     	if(data.code =="2000" ){ 
	     		// alert("ok");
	     	}
	     }, 
	    error : function() {      
	    	alert("error！");  
	    }  
	});
}


/*删除*/
function comment_del(obj,id){
	var sid = id;
	alert(sid);
	$.ajax( {  
		url:'/baby/comment/deleteComment',// 跳转到 action  
		data:{key:sid},  
		type:'post',  
		cache:false,  
		dataType:'json',  
		success:function(data) { 
	     	console.log(data);
	     	if(data.code =="2000" ){ 
	     		alert(data.message);
	     		location.reload(); 
	     	}else{
	     		alert(data.message);
	     	}
	    }, 
	    error : function() {      
	    	alert("异常！");  
		}  
	});
}


var optIDs = '';  
function datadelall(){
	 $("input:checkbox[name='comments']:checked").each(function() { 
	 	optIDs += this.value + ','; 
	 	}); //遍历，用逗号串联   
     	alert(optIDs);

     	$.ajax( {  
		url:'/baby/comment/deleteComment',// 跳转到 action  
		data:{sid:optIDs},  
		type:'post',  
		cache:false,  
		dataType:'json',  
		success:function(data) { 
	     	console.log(data);
	     	if(data.code =="2000" ){ 
	     		location.reload(); 
	     	}else{
	     		alert(data.message);
	     	}
	    }, 
	    error : function() {      
	    	alert("异常！");  
		}  
	});


}

// var documentStrIds="";
// var chkUserInfos=document.getElementsByName("chkUserInfos");
// for(var i=0;i<chkUserInfos.length;i++){
//                  if(documentIds[i].checked){
// 	                documentStrIds+=chkUserInfos[i].value+";";
// 		flag=true;     //表示复选框有被选中的
// 	}
// }
// if(flag){
//          window.location.href="......?documentStrIds="+documentStrIds;  //提交后台 别忘了传参
// }

// var optIDs = '';  
// function GetCheckboxvalues() {   
//          $("input:checkbox[name='OperationID']:checked").each(function() { optIDs += this.value + ','; }); //遍历，用逗号串联   
//            alert(optIDs);            
//        }  
// $.ajax({
// url : '/admin/dellist',//后台处理路径
// type:"POST", //传递方式
//         data:JSON.stringify(optIDs)
// dataType:"json",  
// success:function(data){
//                  window.location.reload();//删除后，自动刷新页面
//        }
// });

</script>
</body>
</html>